<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">
  <title>首页</title>
  <!-- Bootstrap core CSS-->
  <link href="${rc.contextPath}/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <!-- Custom fonts for this template-->
  <link href="${rc.contextPath}/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
  <!-- Page level plugin CSS-->
  <link href="${rc.contextPath}/vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">
  <!-- Custom styles for this template-->
  <link href="${rc.contextPath}/css/sb-admin.css" rel="stylesheet">
  <!--swal弹框样式 -->
  <link rel="stylesheet" href="${rc.contextPath}/css/sweetalert.css">
  <script src="${rc.contextPath}/js/sweetalert.min.js"></script>
</head>

<body class="fixed-nav sticky-footer bg-dark" id="page-top">

 	<div class="container">
                <div class="modal fade" id="myModaluser" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="width: 100%;">
                    <div class="modal-dialog"  style="width: 100%;">
                        <div class="modal-content">
                            <div class="modal-header">
                            <h4 class="modal-title" >
                                    	用户信息
                                </h4>
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                    &times;
                                </button>
                            </div>
                            <div class="modal-body">
                            <form action="" id = "edittable" method="post" >
                              <table id="editUserInfo" style="width: 100%; border-collapse: separate; border-spacing: 0px 15px;">
                              </table>
                              </form>
                            </div>
                            <div class="modal-footer"> <button type="button" onclick="editUser()" class="btn btn-primary">提交更改</button>  <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button></div>
                            </div>
                        </div>
                    </div>
                    </div>
                    
  <!-- Navigation-->
  <!--nav start-->
  <nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top" id="mainNav">
    <a class="navbar-brand" href="index.html">退役军人信息管理系统</a> 
    <div class="collapse navbar-collapse" id="navbarResponsive">
      <ul class="navbar-nav navbar-sidenav" id="exampleAccordion">
        <li class="nav-item" data-toggle="tooltip" data-placement="right" title="信息管理">
          <a class="nav-link" nav-link-collapse collapsed" data-toggle="collapse" href="#infocollapseMulti">
            <i class="fa fa-fw fa-dashboard"></i>
            <span class="nav-link-text">信息管理</span>
          </a>
          <ul class="sidenav-second-level collapse" id="infocollapseMulti">
            <li>
              <a href="index_main1.ftl">信息列表</a>
            </li>
            <li>
              <a href="addInfo.ftl">信息新增</a>
            </li>
          </ul>
        </li>
        <li class="nav-item" data-toggle="tooltip" data-placement="right" title="用户管理">
          <a class="nav-link" nav-link-collapse collapsed" data-toggle="collapse" href="#usercollapseMulti" data-parent="#exampleAccordion">
            <i class="fa fa-fw fa-area-chart"></i>
            <span class="nav-link-text">用户管理</span>
          </a>
          <ul class="sidenav-second-level collapse" id="usercollapseMulti">
            <li>
              <a href="#" onclick="searchuserList()">用户列表</a>
            </li>
            <li>
              <a href="#" onclick="addUser()">新增用户</a>
            </li>
          </ul>
        </li>

        <!--Menu Levels-->
        <li class="nav-item" data-toggle="tooltip" data-placement="right" title="友情链接">
          <a class="nav-link nav-link-collapse collapsed" data-toggle="collapse" href="#collapseMulti" data-parent="#exampleAccordion">
            <i class="fa fa-fw fa-sitemap"></i>
            <span class="nav-link-text">友情链接</span>
          </a>
          <ul class="sidenav-second-level collapse" id="collapseMulti">
            <li>
              <a href="#">政工网站</a>
            </li>
            <li>
              <a href="#">治安网站</a>
            </li>
            <li>
              <a href="#">法制在线</a>
            </li>

          </ul>
        </li>

      </ul>
      <!--最小化左边栏目-->
      <ul class="navbar-nav sidenav-toggler">
        <li class="nav-item">
          <a class="nav-link text-center" id="sidenavToggler">
            <i class="fa fa-fw fa-angle-left"></i>
          </a>
        </li>
      </ul>
      <!--右上角列表-->
     <ul class="navbar-nav ml-right">
      <li class="nav-item">
     <a class="nav-link">
            <i class="fa fa-fw "></i>您好,${user.username}</a>
      </li>
      </ul>
      <ul class="navbar-nav ml-auto">
        <!--退出-->
        <li class="nav-item">
          <a class="nav-link" data-toggle="modal" data-target="#exampleModal">
            <i class="fa fa-fw fa-sign-out"></i>退出</a>
        </li>
      </ul> 
    </div>
  </nav>
<!--nav end-->

  <div class="content-wrapper">

    <div class="container-fluid" >
      <!-- Breadcrumbs-->
      <ol class="breadcrumb">
        <li class="breadcrumb-item">
          <a href="#">管理系统</a>
        </li>
        <li class="breadcrumb-item active" id="toptitle">信息管理</li>
      </ol>

<!-- Icon Cards-->
      <!-- <div class="row">
        <div class="col-xl-3 col-sm-6 mb-3">
         <div class="card text-white bg-primary o-hidden h-100">
            <div class="card-body">
              <div class="mr-5">26 New Messages!</div>
            </div>
            
          </div> 
        </div>
        <div class="col-xl-3 col-sm-6 mb-3">
          <div class="card text-white bg-warning o-hidden h-100">
            <div class="card-body">
              <div class="mr-5">11 New Tasks!</div>
            </div>
          </div>
        </div>
        <div class="col-xl-3 col-sm-6 mb-3">
          <div class="card text-white bg-success o-hidden h-100">
            <div class="card-body">
              <div class="mr-5">123 New Orders!</div>
            </div>
          </div>
        </div>
        <div class="col-xl-3 col-sm-6 mb-3">
          <div class="card text-white bg-danger o-hidden h-100">
            <div class="card-body">
              <div class="mr-5">13 New Tickets!</div>
            </div>
          </div>
        </div>
      </div> -->

      <!-- Area Chart Example-->
      <div class="card mb-3"  id="userListTable1">
        <div class="card-header">
          <i class="fa fa-area-chart"></i>统计分析</div>
        <div class="card-body">
          <div id="container1"></div>
        </div>
        <div class="card-footer small text-muted" id="time1" style="color: blueviolet;"></div>
      </div>

          <!-- Example DataTables Card-->
          <div class="card mb-3" id="userListTable2">
            <div class="card-header">
              <i class="fa fa-table"></i> 综合查询</div>
            <div class="card-body">
              <div class="table-responsive">
                <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                  <thead>
                    <tr>
                      <th>Name</th>
                      <th>Position</th>
                      <th>Office</th>
                      <th>Age</th>
                      <th>Start date</th>
                      <th>Salary</th>
                    </tr>
                  </thead>
                  <tfoot>
                    <tr>
                      <th>Name</th>
                      <th>Position</th>
                      <th>Office</th>
                      <th>Age</th>
                      <th>Start date</th>
                      <th>Salary</th>
                    </tr>
                  </tfoot>
                  <tbody>
                    <tr>
                      <td>Tiger Nixon</td>
                      <td>System Architect</td>
                      <td>Edinburgh</td>
                      <td>61</td>
                      <td>2011/04/25</td>
                      <td>$320,800</td>
                    </tr>
                  
                    <tr>
                      <td>Donna Snider</td>
                      <td>Customer Support</td>
                      <td>New York</td>
                      <td>27</td>
                      <td>2011/01/25</td>
                      <td>$112,000</td>
                    </tr>
                  </tbody>
                </table>
              </div>
            </div>
            <div class="card-footer small text-muted" id="time2" style="color: blueviolet;"></div>
          </div>

    <!-- /.container-fluid-->
    <!-- /.content-wrapper-->
    <footer class="sticky-footer">
      <div class="container">
        <div class="text-center">
          <small>Copyright © 管理系统 2018</small>
        </div>
      </div>
    </footer>
    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
      <i class="fa fa-angle-up"></i>
    </a>
    <!-- Logout Modal-->
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">确定退出?</h5>
            <button class="close" type="button" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
          </div>
          <div class="modal-body">点击'退出'确认退出当前登录账号</div>
          <div class="modal-footer">
            <button class="btn btn-secondary" type="button" data-dismiss="modal">取消</button>
            <a class="btn btn-primary" href="login.html">确定</a>
          </div>
        </div>
      </div>
    </div>
    <!-- Bootstrap core JavaScript-->
    <script src="${rc.contextPath}/vendor/jquery/jquery.min.js"></script>
    <script src="${rc.contextPath}/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
    <!-- Core plugin JavaScript-->
    <script src="${rc.contextPath}/vendor/jquery-easing/jquery.easing.min.js"></script>
    <!-- Page level plugin JavaScript-->
    <script src="${rc.contextPath}/vendor/chart.js/Chart.min.js"></script>
    <script src="${rc.contextPath}/vendor/datatables/jquery.dataTables.js"></script>
    <script src="${rc.contextPath}/vendor/datatables/dataTables.bootstrap4.js"></script>
    <!-- Custom scripts for all pages-->
    <script src="${rc.contextPath}/js/sb-admin.min.js"></script>
    <!-- Custom scripts for this page-->
    <script src="${rc.contextPath}/js/sb-admin-datatables.min.js"></script>
    <script src="${rc.contextPath}/js/sb-admin-charts.min.js"></script>
    <!-- new add highcharts-->
    <script src="${rc.contextPath}/vendor/highcharts/highcharts.js"></script>
    <script src="${rc.contextPath}/vendor/highcharts/highcharts-more.js"></script>
    <script src="${rc.contextPath}/vendor/highcharts/highcharts-3d.js"></script>
    <script src="${rc.contextPath}/vendor/highcharts/exporting.js"></script>
    <script src="${rc.contextPath}/vendor/highcharts/drilldown.js"></script>
    <script src="${rc.contextPath}/vendor/highcharts/data.js"></script>
    <!-- new add scrollspy-->
    <script src="${rc.contextPath}/vendor/scrollspy/util.js"></script>
  </div>
</body>

<script>
  function mytime(){
      var a = new Date();
      var b = a.toLocaleTimeString();
      var c = a.toLocaleDateString();
      document.getElementById("time1").innerHTML = "更新时间:&nbsp"+c+"&nbsp"+b;
      document.getElementById("time2").innerHTML = "更新时间:&nbsp"+c+"&nbsp"+b;
      }
  setInterval(function() {mytime()},1000);
</script>

<script>
    $(function () {
        $.ajax({
            type:"post",
            url :"/user/doLogin?inputEmail="+username+"&inputPassword="+pwd,
            success:function(data){
                if(data.code=="0"){
                    if(data.user.power_id=="1"){
                        window.location.href = "/user/index_main1";
                    }else if(data.user.power_id=="2"){
                        window.location.href = "/user/index_main2";
                    }else {
                        window.location.href = "/user/index_main3";
                    }
                }else if(data.code=="1"){
                    alert("密码错误");
                    swal("密码错误");
                }else if(data.code=="2"){
                    alert("账号不存在");
                }

            }

        });

    });
</script>
<script>
    $(function () {
                var chart11 = Highcharts.chart('container1', {
                    title: {
                        text: '按各区县统计'
                    },
                    credits: {
                        enabled: false
                    },
                    xAxis: {
                        categories: ['山泉区', '山水区', '水山县', '平安县', '有福县', '富有市', '海云市', '人杰县', '地灵区', '丰收县']
                    },
                    yAxis: {
                        title: {
                            text: '人数'
                        }
                    },
                    series: [{
                        name: '人数',
                        type: 'column',
                        colorByPoint: true,
                        // data: {{ jymonth_totalfee2018Arr }},
                        data: [29, 71, 106, 129, 144, 176, 135, 148, 216, 194],
                        showInLegend: false
                    }]
                });
            }
    );
</script>
<script type="text/javascript">
	/*新增用户信息*/
	function addUser(){
	  $("#userListTable1").html("");
	  $("#userListTable2").html("");
      $("#toptitle").text("新增用户");
      var userinfo = '';
      userinfo += '<form action="" type="post" id="saveuserinfo">';
	  userinfo += '<table class="table " id="dataTable" width="100%" >';
	  userinfo += '<tr><td>用户名</td><td>';
	  userinfo += '<input id="username" name="username" type="text" class="form-control" value=""></td></tr><tr><td>密码</td><td>';
	  userinfo += '<input id="psword" name="psword" type="password" class="form-control" value="" ></td></tr><tr><td>权限:</td><td>';
	  userinfo += '<select id="power_id" name="power_id" class="form-control" value="">';
	  userinfo += '<option value="">请选择</option><option value="1">市管理员</option><option value="2">区县管理员</option><option value="3">乡镇管理员</option></td></tr><tr><td>管辖区县</td><td>';
	  userinfo += '<select id="part_id" name="part_id" class="form-control" value="">';
	  userinfo += '<option value="">请选择</option><option value="1">市中区</option><option value="2">市西区</option><option value="3">市东区</option><option value="4">市南区</option><option value="5">市北区</option>';
      userinfo += '</td></tr></table>';
      userinfo +='<center><button type = "button" class="btn-primary" onclick="saveUser()">保存</button></center>';
     userinfo += '</form>';
      $("#userListTable2").html(userinfo);
	}
	function searchuserList(){
	$.ajax({
		type:"post",
		url:"/user/findUserlist",
		success:function(data){
		if(data.code=="0"){
		$("#userListTable1").html("");
		$("#userListTable2").html("");
     	$("#toptitle").text("用户管理");
     	
     	var userTableList = "";
     	userTableList +='<table class="table table-bordered  table-condensed table-hover" id="dataTable" width="100%" cellspacing="0">';
     	userTableList += '<thead><tr><th>用户编号</th><th>用户名</th><th>权限</th><th>管辖区县</th><th>操作</th></tr></thead>';
     	for(var i=0;i<data.userList.length;i++){
     	userTableList += '<tbody><tr><td>'+data.userList[i].user_id+'</td><td>'+data.userList[i].username+'</td><td>';
     		if(data.userList[i].power_id=='1'){
     		userTableList += '市管理员</td><td>';
     		}else if(data.userList[i].power_id=='2'){
     		userTableList += '县区管理员</td><td>';
     		}else if(data.userList[i].power_id=='3'){
     		userTableList += '乡镇管理员</td><td>';
     		}else {
     		userTableList += data.userList[i].power_id+'</td><td>';
     		}
     		if(data.userList[i].part_id=='1'){
     		userTableList += '市中区</td><td>';
     		}else if(data.userList[i].part_id=='2'){
     		userTableList += '市西区</td><td>';
     		}else if(data.userList[i].part_id=='3'){
     		userTableList += '市东区</td><td>';
     		}else if(data.userList[i].part_id=='4'){
     		userTableList += '市南区</td><td>';
     		}else if(data.userList[i].part_id=='5'){
     		userTableList += '市北区</td><td>';
     		}
     		userTableList += "<span><a href='#' onClick=\"return machineOpen('"+data.userList[i].user_id+"');\" " ;
            userTableList += ">修改用户</a></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
     		userTableList += "<span><a href='#' onClick=\"return confirmDeal('"+data.userList[i].user_id+"');\" " ;
            userTableList += ">删除用户</a></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
     	}
     	$("#userListTable2").html(userTableList);
		}else {
		swal("查询失败");
		}
		}
	});
	}
	/*删除用户*/
	function confirmDeal(userId){
	if(confirm("确认删除?")){
	$.ajax({
		type:"post",
		url:"/user/removeUser?userId="+userId,
		success:function(data){
		if(data=="ok"){
		alert("删除成功");
		}else {
		alert("删除失败");
		}
		}
	})
	}
	
	}
	/*查看用户信息*/
	function machineOpen(userid){
	$.ajax({
	type:"post",
	url:"/user/editUser?userId="+userid,
	success:function(data){
	if(data.code=="0"){
	var userinfo = '';
	userinfo += '<tr><td>用户编号:</td><td>';
	userinfo += '<input id="user_id" name="user_id" type="text" class="form-control" value='+data.user.user_id+'></td>';
	userinfo += '</tr><tr><td>用户名</td><td>';
	userinfo += '<input id="username" name="username" type="text" class="form-control" value='+data.user.username+'></td><tr><td>';
	userinfo +='密码</td><td><input id="psword" name="psword" type="password" class="form-control" value='+data.user.psword+'></td><tr><td>';
	userinfo += '权限</td><td>';
	userinfo += '<select id="power_id" name="power_id" class="form-control" value="+data.user.power_id+">';
	userinfo += '<option value="1">市管理员</option><option value="2">区县管理员</option><option value="3">乡镇管理员</option></td><tr><td>管辖区县</td><td>';
	userinfo += '<select id="part_id" name="part_id" class="form-control" value="+data.user.part_id+">';
	userinfo += '<option value="1">市中区</option><option value="2">市西区</option><option value="3">市东区</option><option value="4">市南区</option><option value="5">市北区</option>';
	$("#editUserInfo").html("");
	$("#editUserInfo").html(userinfo);
	 $('#myModaluser').modal('toggle');
	}
	}
	})
	}
	/*保存修改的用户信息*/
	function editUser(){
	var result = $('#edittable').serialize();
	$.ajax({
	type:"post",
	url:"/user/editUserinfo",
	data:result,
	success:function(data){
	if(data=="ok"){
	alert("修改成功");
	 $('#myModaluser').modal('hide');
	}else {
	alert("修改失败");
	}
	}
	})
	}
	/*保存新增的用户信息*/
	function saveUser(){
	alert("新增用户");
	var result = $("#saveuserinfo").serialize();
	$.ajax({
	type:"post",
	url:"/user/saveuserinfo",
	data:result,
	success:function(data){
	if(data=='ok'){
	alert("新增用户成功");
	}else {
	alert("新增失败");
	}
	}
	})
	}
</script>
<script type="text/javascript"></script>
</html>

